/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sales.hanserver.action.hanforpi;

import static br.com.sales.hanserver.dao.Dao.closeConn;
import static br.com.sales.hanserver.dao.Dao.getConn;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Karine
 */
public class ValidateLoginAction {

    public ValidateLoginAction() {
    }

    public Map validateLogin(String user, String password) {
        Map retorno = new LinkedHashMap();
        retorno.put("RETORNO", 0);
        try {
            PreparedStatement st = getConn().prepareStatement(HanForPIServerConsts.GET_LOGIN);
            st.setString(1, user);
            st.setString(2, password);

            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                retorno.put("RETORNO", rs.getInt("ie_existe"));
                retorno.put("TIPO_USUARIO", rs.getInt("ie_tipo_usuario"));
                retorno.put("SITUACAO", rs.getString("ie_situacao"));
            }
        } catch (Exception e) {
            Logger.getLogger(ValidateLoginAction.class.getName()).log(Level.SEVERE, "Error getDataGrid", e);
        } finally {
            closeConn();
        }
        return retorno;
    }

}
